//
//  JQKSwitch.m
//  SwitchDemo
//
//  Created by Xwoder on 2017/9/11.
//  Copyright © 2017年 Xwoder. All rights reserved.
//

#import "JQKSwitch.h"

@implementation JQKSwitch

- (void)sendActionsForControlEvents:(UIControlEvents)controlEvents {
    
    if (controlEvents == UIControlEventValueChanged) {
        _changedByUser = YES;
        if ([self.delegate respondsToSelector:@selector(jqkSwitch:valueChangedByUser:)]) {
            [self.delegate jqkSwitch:self valueChangedByUser:YES];
        }
        !self.valueChangedBlock ? : self.valueChangedBlock(YES);
    }
    
    
    [super sendActionsForControlEvents:controlEvents];
}

- (void)setOn:(BOOL)on animated:(BOOL)animated {
    [super setOn:on animated:animated];
    _changedByUser = NO;
    if ([self.delegate respondsToSelector:@selector(jqkSwitch:valueChangedByUser:)]) {
        [self.delegate jqkSwitch:self valueChangedByUser:NO];
    }
    !self.valueChangedBlock ? : self.valueChangedBlock(NO);
}

@end
